package com.dianshang.controller.order;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dianshang.entity.PageResult;
import com.dianshang.entity.Result;
import com.dianshang.pojo.order.Order;
import com.dianshang.pojo.order.OrderDetail;
import com.dianshang.service.order.OrderService;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Reference
    private OrderService orderService;

    /**
     * 查询所有
     */
    @GetMapping("/findAll")
    public List<Order> findAll(){
        return orderService.findAll();
    }

    /**
     * 发货页面
     * 查询所有+分页(带查询条件)
     * 条件:
     *      发货状态: 没发货
     *      是否删除: 未删除
     *      订单状态: 待发货
     */
    @GetMapping("/findPage")
    public PageResult<Order> findPage(Integer page, Integer size){
        return orderService.findPage(page, size);
    }

    /**
     * 查询所有+模糊
     */
    @PostMapping("/findList")
    public List<Order> findList(@RequestBody Map<String,Object> searchMap){
        return orderService.findList(searchMap);
    }

    /**
     * 查询所有+分页+模糊
     */
    @PostMapping("/findPage")
    public PageResult<Order> findPage(@RequestBody Map<String,Object> searchMap,Integer page, Integer size){
        return  orderService.findPage(searchMap,page,size);
    }

    /**
     * 查询订单组合
     */
    @GetMapping("/findById")
    public OrderDetail findById(String id){
        return orderService.findById(id);
    }

    /**
     * 添加
     */
    @PostMapping("/add")
    public Result add(@RequestBody Order order){
        orderService.add(order);
        return new Result();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public Result update(@RequestBody Order order){
        orderService.update(order);
        return new Result();
    }

    /**
     * 删除
     */
    @GetMapping("/delete")
    public Result delete(Integer id){
        orderService.delete(id);
        return new Result();
    }

    /**
     * 发货
     */
    // 方法一(发货):
    @PostMapping("/batchSend")
    public Result batchSend(@RequestBody Order order) {
        int count = orderService.batchSend(order);
        return new Result(0,"发货成功");
    }
    // 方法二(发货):
    /* @GetMapping("/batchSend")
    public Result batchSend(String id) {
        int count = orderService.batchSend(id);
        return new Result(0,"发货成功");
    } */
    // 方法三(发货):
    /* @PostMapping("/batchSend")
    public Result batchSend(@RequestBody Map<String,String> map) {
        int count = orderService.batchSend(map);
        return new Result(0,"发货成功");
    } */

    /**
     * 批量发货
     */
    // 方法一(批量发货):
    @PostMapping("/batchSendMore")
    public Result batchSendMore(@RequestBody List<Order> orders){
        orderService.batchSendMore(orders);
        return new Result(0,"发货成功");
    }
    // 方法二(批量发货):
    /* @PostMapping("/batchSendMore")
    public Result batchSendMore(@RequestBody String[] ids){
        int count = orderService.batchSendMore(ids);
        return new Result(0,"发"+count+"个快递");
    } */

    /**
     * 合并订单
     */
    @GetMapping("/hebing")
    public Result hebing(String id1,String id2){
        orderService.hebing(id1,id2);
        return new Result();
    }

    /**
     * 拆分订单
     */
    @PostMapping("/chai")
    public Result chai(@RequestBody Map<String,String> map){
        orderService.chai(map);
        return new Result();
    }

}